﻿using BaseUi.Device;
using BaseUi.Models;
using HandyControl.Controls;
using Ping9719.DeviceCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi
{
    /// <summary>
    /// ChangeBoxView.xaml 的交互逻辑
    /// </summary>
    public partial class ChangeBoxView : UserControl
    {
        public ChangeBoxView()
        {
            InitializeComponent();
        }
        public ChangeBan DeviceData1
        {
            get { return (ChangeBan)GetValue(DeviceDataProperty1); }
            set { SetValue(DeviceDataProperty1, value); }
        }

        public static readonly DependencyProperty DeviceDataProperty1 =
            DependencyProperty.Register("DeviceData1", typeof(ChangeBan), typeof(ChangeBoxView), new PropertyMetadata(null));
        public ChangeBan DeviceData2
        {
            get { return (ChangeBan)GetValue(DeviceDataProperty2); }
            set { SetValue(DeviceDataProperty2, value); }
        }

        public static readonly DependencyProperty DeviceDataProperty2 =
            DependencyProperty.Register("DeviceData2", typeof(ChangeBan), typeof(ChangeBoxView), new PropertyMetadata(null));
        public VisionBan VisionBan1
        {
            get { return (VisionBan)GetValue(DeviceDataProperty3); }
            set { SetValue(DeviceDataProperty3, value); }
        }

        public static readonly DependencyProperty DeviceDataProperty3 =
            DependencyProperty.Register("VisionBan1", typeof(VisionBan), typeof(ChangeBoxView), new PropertyMetadata(null));
        public VisionBan VisionBan2
        {
            get { return (VisionBan)GetValue(DeviceDataProperty4); }
            set { SetValue(DeviceDataProperty4, value); }
        }

        public static readonly DependencyProperty DeviceDataProperty4 =
            DependencyProperty.Register("VisionBan2", typeof(VisionBan), typeof(ChangeBoxView), new PropertyMetadata(null));
        private void change(object sender, RoutedEventArgs e)
        {
            try
            {
                var aaa = new Result<string>();
                switch ((sender as Button).Name)
                {
                    
                    case "sapape1":
                        aaa = DeviceData1.Readsent1(2000, LocalFile.Config.Amp1);
                        break;
                    case "sapape2":
                        aaa = DeviceData1.Readsent2(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape3":
                        aaa = DeviceData1.Readsent3(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape4":
                        aaa = DeviceData1.Readsent4(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape5":
                        aaa = DeviceData1.Readsent5(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape6":
                        aaa = DeviceData1.Readsent6(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape7":
                        aaa = DeviceData1.Readsent7(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape8":
                        aaa = DeviceData1.Readsent8(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape9":
                        aaa = DeviceData1.Readsent9(500, LocalFile.Config.Amp1);
                        break;
                    case "sapape10":
                        aaa = DeviceData1.Readsent10(500, LocalFile.Config.Amp1);
                        break;
                    case "sbpape1":
                        aaa = DeviceData1.Readsent1(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape2":
                        aaa = DeviceData1.Readsent2(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape3":
                        aaa = DeviceData1.Readsent3(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape4":
                        aaa = DeviceData1.Readsent4(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape5":
                        aaa = DeviceData1.Readsent5(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape6":
                        aaa = DeviceData1.Readsent6(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape7":
                        aaa = DeviceData1.Readsent7(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape8":
                        aaa = DeviceData1.Readsent8(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape9":
                        aaa = DeviceData1.Readsent9(500, LocalFile.Config.Amp2);
                        break;
                    case "sbpape10":
                        aaa = DeviceData1.Readsent10(500, LocalFile.Config.Amp2);
                        break;

                    case "scpape1":
                        aaa = DeviceData2.Readsent1(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape2":
                        aaa = DeviceData2.Readsent2(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape3":
                        aaa = DeviceData2.Readsent3(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape4":
                        aaa = DeviceData2.Readsent4(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape5":
                        aaa = DeviceData2.Readsent5(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape6":
                        aaa = DeviceData2.Readsent6(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape7":
                        aaa = DeviceData2.Readsent7(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape8":
                        aaa = DeviceData2.Readsent8(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape9":
                        aaa = DeviceData2.Readsent9(500, LocalFile.Config.Amp3);
                        break;
                    case "scpape10":
                        aaa = DeviceData2.Readsent10(500, LocalFile.Config.Amp3);
                        break;

                    case "sdpape1":
                        aaa = DeviceData2.Readsent1(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape2":
                        aaa = DeviceData2.Readsent2(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape3":
                        aaa = DeviceData2.Readsent3(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape4":
                        aaa = DeviceData2.Readsent4(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape5":
                        aaa = DeviceData2.Readsent5(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape6":
                        aaa = DeviceData2.Readsent6(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape7":
                        aaa = DeviceData2.Readsent7(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape8":
                        aaa = DeviceData2.Readsent8(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape9":
                        aaa = DeviceData2.Readsent9(500, LocalFile.Config.Amp4);
                        break;
                    case "sdpape10":
                        aaa = DeviceData2.Readsent10(500, LocalFile.Config.Amp4);
                        break;
                }
                
                if (aaa.IsSucceed)
                {
                        textBoxInfo.AppendText($"成功切换页面" + aaa.Value + "\r\n");
                }
                else
                {
                    textBoxInfo.AppendText($"失败：{aaa.Err}\r\n");
                }
            }
            catch (Exception ex)
            {
                textBoxInfo.AppendText($"错误：{ex.Message}\r\n");
            }
        }

        private void shijue(object sender, RoutedEventArgs e)
        {
            try
            {
                var aaa = new Result<string>();
                string getreal = "";
                switch ((sender as Button).Name)
                {
                    case "shjue1":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision1);
                        break;
                    case "shjue2":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision2);
                        break;
                    case "shjue3":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision3);
                        break;
                    case "shjue4":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision4);
                        break;
                    case "shjue5":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision5);
                        break;
                    case "shjue6":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision6);
                        break;
                    case "shjue7":
                        aaa.Value = VisionBan1.SendMes("s=1;x=3;L"+PortModel.Vision7);
                        break;
                    case "shjue8":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision1);
                        break;
                    case "shjue9":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision2);
                        break;
                    case "shjue10":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision3);
                        break;
                    case "shjue11":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision4);
                        break;
                    case "shjue12":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision5);
                        break;
                    case "shjue13":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision6);
                        break;
                    case "shjue14":
                        aaa.Value = VisionBan2.SendMes("s=1;x=3;R"+PortModel.Vision7);
                        break;
                }

                if (aaa.IsSucceed)
                {
                    if (aaa.Value == getreal)
                    {
                        textBoxInfo.AppendText($"成功" + aaa.Value + "\r\n");
                    }
                    else
                    {

                        textBoxInfo.AppendText($"失败：{aaa.Value}与{getreal}不同\r\n");
                    }
                }
                else
                {
                    textBoxInfo.AppendText($"失败：{aaa.Err}\r\n");
                }
            }
            catch (Exception ex)
            {
                textBoxInfo.AppendText($"错误：{ex.Message}\r\n");
            }
        }
    }
}
